def length_of_longest_substring(s):
    max_length = 0
    start = 0
    char_map = {}

    for end in range(len(s)):
        if s[end] in char_map and char_map[s[end]] >= start:
            start = char_map[s[end]] + 1
        char_map[s[end]] = end
        max_length = max(max_length, end - start + 1)

    return max_length

s1 = "abcabcbb"
s2 = "bbbbb"
s3 = "pwwkew"
print(length_of_longest_substring(s1))
print(length_of_longest_substring(s2))
print(length_of_longest_substring(s3))